package org.jeecg.modules.demo.mpwlwjc.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoDict;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.demo.mpwlwjc.entity.ZwglEventControl;
import org.jeecg.modules.demo.mpwlwjc.service.IZwglEventControlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * @Description: 事件监控
 * @Author: jeecg-boot
 * @Date: 2022-11-26
 * @Version: V1.0
 */
@Api(tags = "事件监控")
@RestController
@RequestMapping("/mpwlwjc/zwglEventControl")
@Slf4j
public class ZwglEventControlController extends JeecgController<ZwglEventControl, IZwglEventControlService> {
    @Autowired
    private IZwglEventControlService zwglEventControlService;

    /**
     * 分页列表查询
     *
     * @param zwglEventControl
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "事件监控-分页列表查询")
    @ApiOperation(value = "事件监控-分页列表查询", notes = "事件监控-分页列表查询")
    @GetMapping(value = "/list")
    @AutoDict
    public Result<IPage<ZwglEventControl>> queryPageList(ZwglEventControl zwglEventControl,
                                                         @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                         @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                         HttpServletRequest req) {
        QueryWrapper<ZwglEventControl> queryWrapper = QueryGenerator.initQueryWrapper(zwglEventControl, req.getParameterMap());
        Page<ZwglEventControl> page = new Page<ZwglEventControl>(pageNo, pageSize);
        IPage<ZwglEventControl> pageList = zwglEventControlService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 添加
     *
     * @param zwglEventControl
     * @return
     */
    @AutoLog(value = "事件监控-添加")
    @ApiOperation(value = "事件监控-添加", notes = "事件监控-添加")
    //@RequiresPermissions("com.nfyszny.zwgl:zwgl_event_control:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody ZwglEventControl zwglEventControl) {
        zwglEventControlService.save(zwglEventControl);
        return Result.OK("添加成功！");
    }


    /**
     * 消息新增
     *
     * @return
     */
    @AutoLog(value = "事件监控-消息新增")
    @ApiOperation(value = "事件监控-消息新增", notes = "事件监控-消息新增")
    @GetMapping(value = "/addNew")
    public Result<String> addNew() {
        ZwglEventControl zwglEventControl = new ZwglEventControl();
        zwglEventControl.setDevictNo("J45489586");
        zwglEventControl.setDecixtName("日光温室控制器");
        zwglEventControl.setEventType("测试类型");
        zwglEventControl.setEventStatus("0");
        zwglEventControlService.save(zwglEventControl);
        return Result.OK("操作成功！");
    }

    /**
     * 编辑
     *
     * @param zwglEventControl
     * @return
     */
    @AutoLog(value = "事件监控-编辑")
    @ApiOperation(value = "事件监控-编辑", notes = "事件监控-编辑")
    //@RequiresPermissions("com.nfyszny.zwgl:zwgl_event_control:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody ZwglEventControl zwglEventControl) {
        zwglEventControlService.updateById(zwglEventControl);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "事件监控-通过id删除")
    @ApiOperation(value = "事件监控-通过id删除", notes = "事件监控-通过id删除")
    //@RequiresPermissions("com.nfyszny.zwgl:zwgl_event_control:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        zwglEventControlService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "事件监控-批量删除")
    @ApiOperation(value = "事件监控-批量删除", notes = "事件监控-批量删除")
    //@RequiresPermissions("com.nfyszny.zwgl:zwgl_event_control:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.zwglEventControlService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "事件监控-通过id查询")
    @ApiOperation(value = "事件监控-通过id查询", notes = "事件监控-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<ZwglEventControl> queryById(@RequestParam(name = "id", required = true) String id) {
        ZwglEventControl zwglEventControl = zwglEventControlService.getById(id);
        if (zwglEventControl == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(zwglEventControl);
    }

    /**
     * 忽略和处理操作
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "事件监控-忽略和处理操作", notes = "事件监控-忽略和处理操作")
    @GetMapping(value = "/handleDealWithData")
    public Result<?> handleDealWithData(@RequestParam(name = "id", required = true) String id,
                                        @RequestParam(name = "index", required = true) String index) {
        return zwglEventControlService.handleDealWithData(id, index);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param zwglEventControl
     */
    //@RequiresPermissions("com.nfyszny.zwgl:zwgl_event_control:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, ZwglEventControl zwglEventControl) {
        return super.exportXls(request, zwglEventControl, ZwglEventControl.class, "事件监控");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    //@RequiresPermissions("zwgl_event_control:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, ZwglEventControl.class);
    }

}
